// 复制文本
import tips from "@/utils/tips";

export const copyText = (text : string) => {
	uni.setClipboardData({
		data: text,
		success: () => {
			tips.showToast('复制成功')
		},
		fail: () => {
			tips.showToast('复制失败')
		}
	});
}

// 跳转页面
export const skip = {
	navigateTo : (url:string) => {
		uni.navigateTo({url})
	},
	switchTab : (url:string) => {
		uni.switchTab({url})
	},
	redirectTo : (url:string) => {
		uni.redirectTo({url})
	},
	navigateBack:(delta:number = 1)=> {
		uni.navigateBack({delta})
	},
	reLaunch:(url:string)=>{
		uni.reLaunch({url})
	}
}

// 转换时间戳
export const transformTime = (time = +new Date()) => {
	let date = new Date(Number(time) + 8 * 3600 * 1000); // 增加8小时
	return date.toJSON().slice(0, 19).replace('T', ' ');
}

/**
 * @description 时间戳转时间
 * @param {Number} date
 * @param {Number} AddDayCount
 * @return {Object} 时间
 */
export const getDate = (date:any, AddDayCount: number = 0): Object => {
	if (!date) {
		date = new Date()
	}
	const dd = new Date(date)

	dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期

	const y = dd.getFullYear()
	const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期，不足10补0
	const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
	const h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours() // 获取时钟，不足10补0
	const mi = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes() // 获取分钟，不足10补0
	const s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds() // 获取秒钟，不足10补0
	return {
		fullDate: y + '-' + m + '-' + d + ' ' + h + ':' + mi + ':' + s,
		year: y,
		month: m,
		date: d,
		hours: h,
		minutes: mi,
		seconds: s,
		day: dd.getDay(),
	}
}


